package org.tio.sitexxx.service.service.gl;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.sitexxx.service.cache.CacheConfig;
import org.tio.sitexxx.service.cache.Caches;
import org.tio.sitexxx.service.model.main.Promoter;
import org.tio.sitexxx.service.vo.Const;
import org.tio.utils.cache.CacheUtils;
import org.tio.utils.cache.FirsthandCreater;
import org.tio.utils.cache.ICache;

public class PromoterManageService {

    private static Logger log	= LoggerFactory.getLogger(PromoterManageService.class);
    public static final PromoterManageService	me	= new PromoterManageService();

    public Page<Promoter> promoterList(int pageNumber,int pageSize){
        String db = Const.Db.TIO_SITE_MAIN;
        String sqlid = "gl_promoter.promoterList";
        ICache cache  = Caches.getCache(CacheConfig.PROMOTER_LIST);
        String key = pageNumber + "_" + pageSize;
        boolean putTempToCacheIfNull  = false;
        Page<Promoter> page = CacheUtils.get(cache, key, putTempToCacheIfNull, new FirsthandCreater<Page<Promoter>>() {
            @Override
            public Page<Promoter> create() {
                SqlPara sqlPara = Db.use(db).getSqlPara(sqlid);
                Page<Promoter> page = Promoter.dao.paginate(pageNumber, pageSize,sqlPara);
                return page;
            }
        });
        return page;
    }
}
